import Vue from "vue";
import VueRouter from "vue-router";
// import store from "../store/index";

Vue.use(VueRouter);

const routes = [
  {
    path: "/",
    redirect: "/index"
  },
  {
    path: "/login",
    name: "login",
    component: () => import("../views/Login.vue")
  },
  {
    path: "/index",
    redirect: "/index/User",
    name: "index",
    // meta: { permission: true },
    component: () => import("../views/Index.vue"),
    beforeEnter: function(to, from, next) {
      if (sessionStorage.getItem("token")) {
        next();
      } else {
        alert("请先登录");
        next("/login");
      }
    },
    children: [
      {
        path: "User",
        redirect: "/index/User/Student",
        name: "User",
        component: () => import("../views/User/User.vue"),
        children: [
          {
            path: "Student",
            name: "学员管理",
            component: () => import("../views/User/Student.vue"),
            meta: ["学员管理"]
          },
          {
            path: "Teacher",
            name: "Teacher",
            component: () => import("../views/User/Teacher.vue")
          },
          {
            path: "AssistTeacher",
            name: "AssistTeacher",
            component: () => import("../views/User/AssistTeacher.vue")
          },
          {
            path: "student-edit",
            name: "StudentEdit",
            component: () => import("../views/User/StudentEdit.vue"),
            meta: ["学员管理", "新增/编辑学员"]
          }
        ]
      },
      {
        path: "Teach",
        redirect: "/index/Teach/CourseManage",
        name: "Teach",
        component: () => import("../views/Teach/Teach.vue"),
        children: [
          {
            path: "CourseManage",
            name: "CourseManage",
            component: () => import("../views/Teach/Course/CourseManage.vue"),
            meta: ["课程管理"]
          },
          {
            path: "CourseCatagory",
            name: "CourseCatagory",
            component: () => import("../views/Teach/Course/CourseCatagory.vue")
          },
          {
            path: "ClassPlan",
            name: "ClassPlan",
            component: () => import("../views/Teach/Class/ClassPlan.vue")
          },
          {
            path: "ClassManage",
            name: "ClassManage",
            component: () => import("../views/Teach/Class/ClassManage.vue")
          },
          {
            path: "HomeworkManage",
            name: "HomeworkManage",
            component: () => import("../views/Teach/Class/HomeworkManage.vue")
          },
          {
            path: "TeachOtoTable",
            name: "TeachOtoTable",
            component: () => import("../views/Teach/Class/TeachOtoTable.vue")
          }
        ]
      },
      {
        path: "Question",
        name: "Question",
        component: () => import("../views/Question/Question.vue")
      },
      {
        path: "Operation",
        name: "Operation",
        component: () => import("../views/Operation/Operation.vue")
      },
      {
        path: "Market",
        name: "Market",
        component: () => import("../views/Market/Market.vue")
      },
      {
        path: "Shop",
        name: "Shop",
        component: () => import("../views/Shop/Shop.vue")
      },
      {
        path: "Finance",
        name: "Finance",
        component: () => import("../views/Finance/Finance.vue")
      },
      {
        path: "Statistics",
        name: "Statistics",
        component: () => import("../views/Statistics/Statistics.vue")
      },
      {
        path: "Setting",
        name: "Setting",
        component: () => import("../views/Setting/Setting.vue")
      }
    ]
  }
];

const router = new VueRouter({
  routes
});

// router.beforeEach((to, from, next) => {
//   if (to.meta.permission) {
//     if (sessionStorage.getItem("token")) {
//       next();
//     } else {
//       alert("请先登录");
//       next("/login");
//     }
//   } else {
//     next();
//   }
// });

// router.afterEach((to, from) => {
//   // to and from are both route objects.
// });

export default router;
